home *** CD-ROM | disk | FTP | other *** search
- /* SAT Toolbox*/
- /*This unit holds a set of utility routines that may simplify your sprite programming,*/
- /*but that are in no way mandatory.*/
-
- /*MoveSprite: Moves a sprite according to speed*/
- /*KeepOnScreen: Performs border checks for a sprite*/
- /*RectSeparate: Moves two sprites apart*/
- /*RegionHit: Checks if the regions of two sprites overlap*/
- /*SplitVector: A utility for splitting a vector in components parallel and*/
- /*perpendicular to another vector*/
- /**/
- /*Sinus, Cosinus, SquareRoot: Useful look-up table based operations.*/
-
- #ifndef __SATToolbox__
-
- #define __SATToolbox__
-
- #include <SAT.h>
-
- /* Sprite record for sprites with fixed-point movement */
-
- typedef struct {
- /* Variables that you should change as appropriate */
- short kind; /* Used for identification. >0: friend. <0 foe */
- Point position;
- Rect hotRect, hotRect2; /* Tells how large the sprite is; hotRect is centered around origo */
- /*hotRect is set by you. hotRect2 is offset to the current position.*/
- FacePtr face; /* Pointer to the Face (appearance) to be used. */
- ProcPtr task; /* Callback-routine, called once per frame. If task=nil, the sprite is removed. */
- ProcPtr hitTask; /* Callback in collisions. */
- ProcPtr destructTask; /* Called when a sprite is disposed. (Usually nil.) */
- RgnHandle clip; /*Clip region to be used when this sprite is drawn.*/
- /* SAT variables that you shouldn't change: */
- Point oldpos; /*Used by RunSAT2*/
- SpritePtr next, prev; /*You may change them in your own sorting routine, but be careful if you do.*/
- Rect r, oldr; /*Rectangle telling where to draw. Avoid messing with it.*/
- FacePtr oldFace; /*Used by RunSAT2*/
- Boolean dirty; /*Used by RunSAT2*/
- /*Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default*/
- /*set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately*/
- /*after initializing (before any sprites are created)!*/
- short layer; /*For layer-sorting. When not used for that, use freely.*/
- Point speed; /* Can be used for speed, but not necessarily. */
- short mode; /* Usually used for different modes and/or to determine what image to show next. */
- Point fixedPointPosition; /*fixed point position*/
- long appLong; /*Longint for free use by the application.*/
- } FixSprite, *FixSpritePtr;
-
- /*Constants for separation/bounceoff between sprites*/
-
- #define kPushBoth 0
- #define kPushMe 1
- #define kPushHim 2
-
- /*Sprite utilities*/
- pascal void MoveSprite(SpritePtr theSprite);
- pascal Boolean KeepOnScreen(SpritePtr theSprite);
- pascal void MoveSpriteFixedPoint(FixSpritePtr theSprite);
- pascal Boolean KeepOnScreenFixed(FixSpritePtr theSprite);
- pascal Boolean KeepSpriteInRect(SpritePtr theSprite, Rect r);
- pascal short RectSeparate(SpritePtr theSprite, SpritePtr anotherSprite, short push);
- pascal void RectBounce(SpritePtr me, SpritePtr him, short push);
- pascal void RectBounceFixed(FixSpritePtr me, FixSpritePtr him, short push);
- pascal Boolean PtInSpriteRgn(Point p, SpritePtr theSprite);
- pascal Boolean RegionHit(SpritePtr theSprite, SpritePtr anotherSprite);
- pascal void SplitVector(Point v, Point d, Point * p, Point * n);
- pascal Boolean RegionBounce(FixSpritePtr s1, FixSpritePtr s2, short elasticity);
- pascal Boolean RegionBounce2(FixSpritePtr s1, FixSpritePtr s2, short elasticity);
-
- /* Don't change these constants without changing it in SATToolbox.p*/
- /* (and recompiling the lib if you use one)!*/
-
- #define kFixedPointShift 4 /*Number of fixed-point positions*/
- #define kFixedOne 16 /*The "one" in the fixed-point system being used!*/
-
- pascal void InitTables();
- pascal long SquareRoot(long arg);
- pascal long Sinus(long arg);
- pascal long Cosinus(long arg);
- pascal long VectorLength(Point vector);
- pascal long FPVectorLength(Point vector);
- pascal long ApproxVectorLength(Point vector);
-
-
- #endif
-